<template>
  <div class="comment-reply">
    <van-nav-bar :title="replyComment.reply_count ? `${replyComment.reply_count}条回复` : 暂无回复">
      <van-icon slot="left" name="cross" @click="$emit('close')" />
    </van-nav-bar>
    <div class="scorll-comment">
      <!-- 当前评论项 -->
      <CommentItem :comment="replyComment"></CommentItem>
      <van-cell>评论回复</van-cell>
      <CommontList type="c" :scurce="replyComment.com_id" :list="commentList"></CommontList>
    </div>
    <!-- 底部发布评论区域 -->
    <div class="post-comment">
      <van-button round class="post-btn" size="small" @click="popupShow = true">发布评论</van-button>
    </div>
    <!-- 发布评论 -->
    <van-popup v-model="popupShow" position="bottom">
      <!-- 发布组件 -->
      <CommentPost :target="replyComment.com_id" @post-success="postSuccess"></CommentPost>
    </van-popup>
  </div>
</template>

<script>
import CommentItem from './comment-item'
import CommontList from './comment-list'
import CommentPost from './comment-post'
export default {
  name: 'commentReply',
  props: {
    replyComment: {
      type: Object,
      require: true
    }
  },
  components: {
    CommentItem,
    CommontList,
    CommentPost
  },
  data() {
    return {
      popupShow: false,
      commentList: [] //发布的值
    }
  },
  methods: {
    postSuccess(data) {
      // 更新回复数量
      this.replyComment.reply_count++
      //关闭弹出层
      this.popupShow = false
      //将发布内容显示到列表顶部
      this.commentList.unshift(data.new_objg)
    }
  }
}
</script>

<style lang="less" scoped>
.comment-reply {
  .scorll-comment {
    position: fixed;
    top: 92px;
    left: 0;
    right: 0;
    bottom: 88px;
    overflow-y: auto;
  }
  .post-comment {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    border-top: 1px solid #d8d8d8;
    .post-btn {
      width: 60%;
    }
  }
}
</style>
